package com.kiwilss.aopdemo.ui.dsl

import android.widget.TableLayout
import com.google.android.material.tabs.TabLayout

/**
 * @author : Administrator
 * e-mail : kiwilss@163.com
 * time   : 2021/02/05
 *  desc   : TabLayout监听扩展
 */

fun onTabSelectedListener(function: OnTabselectListenerBuilder.() -> Unit){
    OnTabselectListenerBuilder().also(function)
}



private typealias OnTabLayoutCallback = (tab: TabLayout.Tab?) -> Unit

class OnTabselectListenerBuilder: TabLayout.OnTabSelectedListener {
    private var onTabReselectedCallback: OnTabLayoutCallback? = null
    private var onTabUnselectedCallback: OnTabLayoutCallback? = null
    private var onTabSelectedCallback: OnTabLayoutCallback? = null

    override fun onTabReselected(tab: TabLayout.Tab?) {
        onTabReselectedCallback?.invoke(tab)
    }

    override fun onTabUnselected(tab: TabLayout.Tab?) {
        onTabUnselectedCallback?.invoke(tab)
    }

    override fun onTabSelected(tab: TabLayout.Tab?) {
        onTabSelectedCallback?.invoke(tab)
    }

    fun onTabReselected(callback: OnTabLayoutCallback){
        onTabReselectedCallback = callback
    }
    fun onTabUnselected(callback: OnTabLayoutCallback){
        onTabUnselectedCallback = callback
    }
    fun onTabSelected(callback: OnTabLayoutCallback){
        onTabSelectedCallback = callback
    }

}

